{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import torch\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from main import load_data\n",
    "from gnn import GCN, eval, adjmat_to_graph\n",
    "from torch.nn import Softmax\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def experiment_GCN(data_name, euc_th, wl_th, num_labels, seed):\n",
    "\n",
    "    X, L, labels, W_x, _,_,_ = load_data(data_name = data_name, euc_th = euc_th, wl_th = wl_th, seed = seed)\n",
    "    # Random label\n",
    "    np.random.seed(seed)\n",
    "    labeled_inds = np.random.choice(range(len(X)), size=num_labels, replace=False)\n",
    "    g = adjmat_to_graph(W_x, X, labels, labeled_inds)\n",
    "    acc, final_pred = eval(g)\n",
    "    softmax = Softmax()\n",
    "    with torch.no_grad():\n",
    "        pseudo_labels = softmax(final_pred)[:,1]\n",
    "    print('Acc :', ((pseudo_labels > 0.5001).long() == labels).float().mean())\n",
    "    return pseudo_labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Acc : tensor(0.8346)\n"
     ]
    }
   ],
   "source": [
    "pseudo_labels = experiment_GCN('youtube', euc_th = 10, wl_th = 10, num_labels = 100, seed = 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([0.2351, 0.7936, 0.3052,  ..., 0.0440, 0.2640, 0.1343])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pseudo_labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "39ca8058bc909080e5cc8b58cc5496375c0141f717bb9f1bcad8ab5053b7d3f8"
  },
  "kernelspec": {
   "display_name": "Python 3.9.7 ('nn-pruning')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
